angular.module('meHistoryListservices', [])

  .factory('MeHistoryList', function ($resource, $rootScope, ENV) {

    //设置访问接口路径
    var APIUrl = ENV.api;

    //访问获取用户信息的接口
    var historyWineListResource = $resource(APIUrl + "meHistoryWine/getHistoryWineList.do");
    var delHistoryWineListResource = $resource(APIUrl + "meHistoryWine/delHistoryWineList.do");
    var searchWineOrderByNameResource = $resource(APIUrl + "meHistoryWine/searchWineOrderByName.do");


    var historyWindListJson;
    var deleteOrdersJson;
    var searchWineOrderByNameJson,goFromCreate;

    return {

      setGo2CreateRe:function(flag){
        goFromCreate = flag;
      },
      getIsGoBack2:function(){
        return goFromCreate;
      },
      //获取会员的历史酒单
      getHistoryWineList : function (memberId) {
        historyWineListResource.save(
          {member_id : memberId},
          function (data) {
            historyWindListJson = data;
            $rootScope.$broadcast('Me.getHistoryWineList');
          }
        );
      },

      getHistoryWineListJson : function (){
        return historyWindListJson;
      },

      //删除对应的酒单
      deleteOrders : function (memberId,deleteOrderIdList){
        delHistoryWineListResource.save(
          {
            member_id : memberId,
            orderIdList : deleteOrderIdList
          }, function (data) {
            deleteOrdersJson = data;
            $rootScope.$broadcast('Me.deleteHistoryOrders');
          }
        );
      },
      getDeleteOrdersJson : function (){
        return deleteOrdersJson;
      },

      // 根据关键字搜索历史酒单
      searchWineOrderByName : function (text){
        searchWineOrderByNameResource.save(
          {mrw_name : text},
          function (data) {
            searchWineOrderByNameJson = data;
            $rootScope.$broadcast('Me.searchWineOrder');
          }

        );
      },
      getSearchWineOrderByName :function (){
        return searchWineOrderByNameJson;
      }

    }

  });
